/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2023-11-24
 * Time: 8:32
 */
class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
public class MyArray <T>{
    //定义一个Object类的数组
    public Object[] objects = new Object[10];
    //用这个Setvalue()方法将内容存放再Object数组中
    public void Setvalue(int pos,T value) {
        objects [pos] = value;
    }
    //用于存放Animal类的内容
   /* public void SetvalueAnimal(int pos, Animal value) {
        objects [pos] = value;
    }*/
    //将存放到Object数组的内容打印出来
    public T Getvalue (int pos) {
        return (T)objects[pos];
    }

    public static void main(String[] args) {
        //可以在数组中存放字符串内容
        MyArray <String> myArray = new MyArray();
        myArray.Setvalue(0,"12345");
        myArray.Setvalue(1,"123456");
        myArray.Setvalue(2,"hello bit");
        String str = myArray.Getvalue(2);
        System.out.println(str);

        //可以在数组中存放整型包装类
        MyArray <Integer> myArray1 = new MyArray();
        myArray1.Setvalue(0,1);
        myArray1.Setvalue(1,2);
        Integer ii = myArray1.Getvalue(0);
        System.out.println(ii);
        //甚至可以存放其他类的内容，例如Animal类
        MyArray <Animal> myArray2 = new MyArray();
        Animal animal = new Animal("小黄",1);
        myArray2.Setvalue(0,animal);
        Animal AA =  myArray2.Getvalue(0);
        System.out.print(AA.name+" ");
        System.out.print(AA.age);
    }
}
